/**
 * MapTest.java - 2012-8-10
 *
 * Licensed Property to China UnionPay Co., Ltd.
 * 
 * (C) Copyright of China UnionPay Co., Ltd. 2010
 *     All Rights Reserved.
 *
 * Project Info: China UnionPay Internet Acquiring Project
 * 
 * Modification History:
 * =============================================================================
 *   Author         Date          Description
 *   ------------ ---------- ---------------------------------------------------
 *        
 * =============================================================================
 */
package com.lijin.study.java.ds;

import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;

import org.junit.Test;

/**
 * Description:
 * 
 * (C) Copyright of China UnionPay Co., Ltd. 2010.
 * 
 */
public class MapTest {

	@Test
	public void testLinkedMap() {
		Map<String, Integer> map = new LinkedHashMap<String, Integer>();
		long ts = System.currentTimeMillis();
		for (int i = 1; i < 2000000; i++) {
			map.put(String.valueOf(i), i);
		}
		System.out.println(System.currentTimeMillis() - ts);

		ts = System.currentTimeMillis();
		map = new HashMap<String, Integer>();
		for (int i = 1; i < 2000000; i++) {
			map.put(String.valueOf(i), i);
		}
		System.out.println(System.currentTimeMillis() - ts);
	}

	@Test
	public void testTreeMap() {
		Map<String, String> tempMap = new TreeMap<String, String>();
		tempMap.put("13", "13-val");
		tempMap.put("01", "01-val");
		tempMap.put("02", "02-val");
		tempMap.put("99", "99-val");
		tempMap.put("00", "00-val");
		System.out.println(tempMap);
		
		Map<String, String> tempMap2 = new TreeMap<String, String>(new Comparator<String>() {
			public int compare(String obj1, String obj2) {
				// 升序排序
				try {
					return Integer.valueOf(obj1).compareTo(Integer.valueOf(obj2)); // 对数字值
				} catch (Exception e) {
					return obj1.compareTo(obj2);
				}
			}
		});
		tempMap2.put("13", "13-val");
		tempMap2.put("01", "01-val");
		tempMap2.put("02", "02-val");
		tempMap2.put("99", "99-val");
		tempMap2.put("00", "00-val");
		System.out.println(tempMap2);
	}
}
